package com.youku.plugins.programListV4.view.items
{
   import flash.display.Sprite;
   import com.youku.interfaces.IProgramData;
   import com.youku.baseUI.BasePlayerButton;
   import flash.text.TextField;
   import com.youku.plugins.PluginEventDispather;
   import flash.text.TextFormat;
   import flash.events.MouseEvent;
   import com.youku.plugins.programListV4.view.event.ProgramListEvent;
   import com.youku.utils.AssetUtil;
   import com.youku.skin.YaheiFontManager;
   
   public class ProgramListParts extends Sprite
   {
      
      public function ProgramListParts(param1:IProgramData) {
         super();
         this._data = param1;
         this._eventManager = PluginEventDispather.getInstance();
         this._btn = AssetUtil.getStyleButton("P_item");
         AssetUtil.restoreButtonSize(this._btn);
         this.addChild(this._btn);
         this._textFormatLight = new TextFormat();
         this._textFormatLight.color = 2236962;
         this._textFormatLight.bold = true;
         this._textFormatOver = new TextFormat();
         this._textFormatOver.color = 2236962;
         this._textFormatOut = new TextFormat();
         this._textFormatOut.color = 12303291;
         this._textFormatDisable = new TextFormat();
         this._textFormatDisable.color = 3355443;
         var _loc2_:* = "";
         if(this._data.type == "VCR")
         {
            _loc2_ = this._data.title;
         }
         if(this._data.type == "TVS")
         {
            _loc2_ = "第" + String(this._data.position) + "集";
         }
         this._titleTextField = AssetUtil.getTextField();
         this._titleTextField.width = 270;
         this._titleTextField.height = 25;
         this._titleTextField.x = 5;
         this._titleTextField.y = 10;
         this._titleTextField.defaultTextFormat = new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,14,12303291);
         this._titleTextField.text = _loc2_;
         this._titleTextField.mouseEnabled = false;
         this.addChild(this._titleTextField);
         if(this._data.videoID == "")
         {
            this._btn.enabled = false;
            this._titleTextField.setTextFormat(this._textFormatDisable);
         }
         else
         {
            this.addEvents();
         }
      }
      
      private var _data:IProgramData;
      
      private var _btn:BasePlayerButton;
      
      private var _titleTextField:TextField;
      
      private var _eventManager:PluginEventDispather;
      
      private var _textFormatLight:TextFormat;
      
      private var _textFormatOver:TextFormat;
      
      private var _textFormatOut:TextFormat;
      
      private var _textFormatDisable:TextFormat;
      
      private var _isActive:Boolean;
      
      private function addEvents() : void {
         this._btn.addEventListener(MouseEvent.MOUSE_OVER,this.onMouse);
         this._btn.addEventListener(MouseEvent.MOUSE_OUT,this.onMouse);
         this._btn.addEventListener(MouseEvent.CLICK,this.onMouse);
      }
      
      private function onMouse(param1:MouseEvent) : void {
         switch(param1.type)
         {
            case MouseEvent.MOUSE_OVER:
               this._titleTextField.setTextFormat(this._textFormatOver);
               break;
            case MouseEvent.MOUSE_OUT:
               if(!this._isActive)
               {
                  this._titleTextField.setTextFormat(this._textFormatOut);
               }
               else
               {
                  this._titleTextField.setTextFormat(this._textFormatLight);
               }
               break;
            case MouseEvent.CLICK:
               this._eventManager.dispatchEvent(new ProgramListEvent(ProgramListEvent.PROGRAM_LIST_CLICK,this._data));
               break;
         }
      }
      
      public function active() : void {
         this._titleTextField.setTextFormat(this._textFormatLight);
         this._btn.enabled = false;
         this._isActive = true;
      }
      
      public function redraw() : void {
         if(!this._isActive)
         {
            this._titleTextField.setTextFormat(this._textFormatOut);
         }
         else
         {
            this._titleTextField.setTextFormat(this._textFormatLight);
         }
      }
      
      private function removeEvents() : void {
         this._btn.removeEventListener(MouseEvent.MOUSE_OVER,this.onMouse);
         this._btn.removeEventListener(MouseEvent.MOUSE_OUT,this.onMouse);
         this._btn.removeEventListener(MouseEvent.CLICK,this.onMouse);
      }
   }
}
